"use strict";
cc._RF.push(module, '593efaXJj1FmrUqVN+Z8VAx', 'BoxGetItem');
// scripts/BoxGetItem.js

"use strict";

var t = require;
var e = module;
var o = exports;

var _i,
    n = void 0 && (void 0).__extends || (_i = function i(t, e) {
  return (_i = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _i(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    a = void 0 && (void 0).__decorate || function (t, e, o, i) {
  var n,
      a = arguments.length,
      r = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);else for (var s = t.length - 1; s >= 0; s--) {
    (n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
  }
  return a > 3 && r && Object.defineProperty(e, o, r), r;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var r = t("CarConstant"),
    s = t("GlobalUserData"),
    l = t("Util"),
    c = t("Global"),
    d = cc._decorator,
    h = d.ccclass,
    p = d.property,
    u = function (t) {
  function e() {
    var e = null !== t && t.apply(this, arguments) || this;
    return e.frame_body = null, e.frame_wheel = null, e.frame_weapon = null, e.frame_tools = null, e.frame_gold = null, e.frame_diamond = null, e.arrNode_body = new Array(), e.arrNode_wheel = new Array(), e.arrNode_weapon = new Array(), e.arrNode_tools = new Array(), e.bodyEquip_frame = null, e.bodyWheel_frame0 = null, e.bodyWheel_frame1 = null, e.bodyWeapon_frame0 = null, e.bodyTools_frame0 = null, e.frame_star = null, e.frame_labNum = null, e.arrNode_star = new Array(5), e.arr_starIcons = new Array(), e.curShowItemNode = null, e.comData = null, e._callback = null, e.nodeWidth = 208, e.space = 20, e._itemType = null, e;
  }

  return n(e, t), e.prototype.start = function () {}, e.prototype.initView = function () {
    this.frame_body.active = !1, this.frame_wheel.active = !1, this.frame_weapon.active = !1, this.frame_tools.active = !1, this.frame_gold.active = !1, this.frame_diamond.active = !1, this.frame_star.active = !1, this.frame_labNum.node.active = !1, this.showBodyEquipFrame(!1), this.setStarQuality();
  }, e.prototype.updateView = function (t, e, o) {
    var i = this;

    switch (void 0 === e && (e = !1), void 0 === o && (o = null), this.initView(), this.setActive(!0), this.showStar(t.star), this._callback = o, this._itemType = t.type, this.curShowItemNode && (this.curShowItemNode.active = !1), t.type) {
      case r.Basics_Items_Type.body:
        var n = r.getBodyData(t.id).index;
        this.frame_body.active = !0;

        for (var a = 1, d = 0; d < this.arrNode_body.length; d++) {
          d == n ? (a = this.arrNode_body[d].scale, this.arrNode_body[d].active = !0, this.curShowItemNode = this.arrNode_body[d], t.quality == c.Quality.epic && (this.setStarQuality(t.quality), l.Util.setBodyParts(this.arrNode_body[d], s["default"].pbf_partsArr[d]))) : this.arrNode_body[d].active = !1;
        }

        this.showBodyEquipFrame(!0, t.id, a);
        break;

      case r.Basics_Items_Type.wheel:
        var h = r.getWheelData(t.id).index;

        for (this.frame_wheel.active = !0, d = 0; d < this.arrNode_wheel.length; d++) {
          this.arrNode_wheel[d].active = d == h, this.arrNode_wheel[d].active && (this.curShowItemNode = this.arrNode_wheel[d]);
        }

        break;

      case r.Basics_Items_Type.weapon:
        var p = null != r.getWeaponData(t.id) ? r.getWeaponData(t.id).index : t.index;

        for (this.frame_weapon.active = !0, this.setStarQuality(t.quality), d = 0; d < this.arrNode_weapon.length; d++) {
          this.arrNode_weapon[d].active = d == p, this.arrNode_weapon[d].active && (this.curShowItemNode = this.arrNode_weapon[d]);
        }

        this.scheduleOnce(function () {
          if (i.curShowItemNode) {
            var t = i.curShowItemNode.width / i.curShowItemNode.height;
            i.curShowItemNode.width > 220 && (i.curShowItemNode.width = 220, i.curShowItemNode.height = 220 / t);
          }
        }, .3);
        break;

      case r.Basics_Items_Type.tools:
        var u = r.getToolsData(t.id).index;

        for (this.frame_tools.active = !0, this.setStarQuality(t.quality), d = 0; d < this.arrNode_tools.length; d++) {
          this.arrNode_tools[d].active = d == u, this.arrNode_tools[d].active && (this.curShowItemNode = this.arrNode_tools[d]);
        }

        break;

      case r.Basics_Items_Type.gold:
        this.frame_gold.active = !0, this.frame_labNum.node.active = !0, t.num ? this.frame_labNum.string = "x " + t.num : this.frame_labNum.string = "";
        break;

      case r.Basics_Items_Type.diamond:
        this.frame_diamond.active = !0, this.frame_labNum.node.active = !0, t.num ? this.frame_labNum.string = "x " + t.num : this.frame_labNum.string = "";
    }

    e && (this.setStarQuality(t.quality), this.comData = {
      type: t.type,
      id: t.id,
      quality: t.quality,
      star: t.star
    }, l.Util.comparison(this.comData) || this.setColor(cc.Color.BLACK));
  }, e.prototype.setColor = function (t) {
    this.curShowItemNode && this.setColorRecur(this.curShowItemNode.parent, t);
  }, e.prototype.setColorRecur = function (t, e) {
    for (var o = 0; o < t.children.length; o++) {
      var i = t.children[o];
      i.color = e, this.setColorRecur(i, e);
    }
  }, e.prototype.setStarQuality = function (t) {
    void 0 === t && (t = 0);

    for (var e = 0; e < this.arrNode_star.length; e++) {
      this.arrNode_star[e].getComponent(cc.Sprite).spriteFrame = this.arr_starIcons[t];
    }
  }, e.prototype.showBodyEquipFrame = function (t, e, o) {
    if (this.bodyWheel_frame0.active = t, this.bodyWheel_frame1.active = t, this.bodyWeapon_frame0.active = t, this.bodyTools_frame0.active = t, t) {
      this.bodyEquip_frame.scale = o;
      var i = r.GetCarBodyData(e);
      this.bodyWheel_frame0.position = i.wheelPos[0], this.bodyWheel_frame1.position = i.wheelPos[1], this.bodyWeapon_frame0.position = i.weaponPos[0], this.bodyTools_frame0.position = i.toolsPos[0];
    }
  }, e.prototype.setPos = function (t, e) {
    if (t && 1 != t) {
      var o;
      o = t % 2 == 1 ? (e - Math.floor(t / 2)) * (this.nodeWidth + this.space) : (e - Math.floor(t / 2) + .5) * (this.nodeWidth + this.space), this.node.position = cc.v3(o, 0, 0);
    } else this.node.position = cc.v3(0, 0, 0);
  }, e.prototype.setActive = function (t) {
    this.node.active = t;
  }, e.prototype.getItemType = function () {
    return this._itemType;
  }, e.prototype.getState = function () {}, e.prototype.onClose = function () {
    this.node.destroy();
  }, e.prototype.showStar = function (t) {
    if (t) {
      this.frame_star.active = !0;
      var e;
      e = t % 2 == 1 ? [cc.v3(0, 0, 0), cc.v3(22, 0, 0), cc.v3(-22, 0, 0), cc.v3(43, 0, 0), cc.v3(-43, 0, 0)] : [cc.v3(11, 0, 0), cc.v3(-11, 0, 0), cc.v3(32, 0, 0), cc.v3(-32, 0, 0)];

      for (var o = 0; o < this.arrNode_star.length; o++) {
        o < t ? (this.arrNode_star[o].active = !0, this.arrNode_star[o].position = e[o]) : this.arrNode_star[o].active = !1, this.arrNode_star[o].scale = .65;
      }

      this.comData && (this.comData.star = t, this._callback && this._callback(this.comData), l.Util.comparison(this.comData) ? this.setColor(cc.Color.WHITE) : this.setColor(cc.Color.BLACK));
    } else this.frame_star.active = !1;
  }, a([p(cc.Node)], e.prototype, "frame_body", void 0), a([p(cc.Node)], e.prototype, "frame_wheel", void 0), a([p(cc.Node)], e.prototype, "frame_weapon", void 0), a([p(cc.Node)], e.prototype, "frame_tools", void 0), a([p(cc.Node)], e.prototype, "frame_gold", void 0), a([p(cc.Node)], e.prototype, "frame_diamond", void 0), a([p(cc.Node)], e.prototype, "arrNode_body", void 0), a([p(cc.Node)], e.prototype, "arrNode_wheel", void 0), a([p(cc.Node)], e.prototype, "arrNode_weapon", void 0), a([p(cc.Node)], e.prototype, "arrNode_tools", void 0), a([p(cc.Node)], e.prototype, "bodyEquip_frame", void 0), a([p(cc.Node)], e.prototype, "bodyWheel_frame0", void 0), a([p(cc.Node)], e.prototype, "bodyWheel_frame1", void 0), a([p(cc.Node)], e.prototype, "bodyWeapon_frame0", void 0), a([p(cc.Node)], e.prototype, "bodyTools_frame0", void 0), a([p(cc.Node)], e.prototype, "frame_star", void 0), a([p(cc.Label)], e.prototype, "frame_labNum", void 0), a([p(cc.Node)], e.prototype, "arrNode_star", void 0), a([p([cc.SpriteFrame])], e.prototype, "arr_starIcons", void 0), a([h], e);
}(cc.Component);

o["default"] = u;

cc._RF.pop();